package com.alipear.shopcredit.common.view.wrapper;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.alipear.appbase.BaseApp;
import com.alipear.ppwhere.common.R;

/**
 * Created by zoulinlin123 on 15/5/8.
 */
public class ListViewCellGroup {
    LinearLayout mCurGroup;
    public ListViewCellGroup(LinearLayout layout) {
        mCurGroup = layout;
    }

    public ListViewCellGroup() {
        mCurGroup = (LinearLayout)getLayoutInflater().
                inflate(R.layout.listview_cell_group, null);
    }


    public ListViewCellGroup addListViewCell(String title, View.OnClickListener listener) {
        mCurGroup.addView(new ListCellViewWrapper(getLayoutInflater().
                inflate(R.layout.listview_cell_view, null)).setTitle(title).
                setOnClickListener(listener).getRootView());
        return this;
    }

    public ListViewCellGroup addListViewCell(String title, View rightView, View.OnClickListener listener) {
        mCurGroup.addView(new ListCellViewWrapper(getLayoutInflater().
                inflate(R.layout.listview_cell_view, null)).setTitle(title).setRightView(rightView).
                setOnClickListener(listener).getRootView());
        return this;
    }

    public ListViewCellGroup addListViewCell(String title, String rightInfo, View.OnClickListener listener) {
        ListCellViewWrapper viewWrapper = new ListCellViewWrapper(getLayoutInflater().
                inflate(R.layout.listview_cell_view, null)).setTitle(title).setInfo(rightInfo);
        mCurGroup.addView(viewWrapper.getRootView());

        if (listener != null) {
            viewWrapper.setOnClickListener(listener);
        }
        else {
            viewWrapper.setRightArrowEnabled(false);
        }
        return this;
    }


    public ListViewCellGroup addListViewCell(String title, View rightView) {
        mCurGroup.addView(new ListCellViewWrapper(getLayoutInflater().
                inflate(R.layout.listview_cell_view_rightview, null)).setTitle(title).
                setRightView(rightView).getRootView());
        return this;
    }

    public ListViewCellGroup addSpliter() {
        mCurGroup.addView(getLayoutInflater().inflate(R.layout.listview_cell_splitter, null));
        return this;
    }

    public LinearLayout getCurGroup() {
        return mCurGroup;
    }


    public static LayoutInflater getLayoutInflater() {
        return LayoutInflater.from(BaseApp.getCurApp().getApplicationContext());
    }

}